﻿using DryIoc;
using Module20240909.Event;
using Prism.Events;
using System;
using System.Windows;

namespace Demo20240909.Views
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private readonly IEventAggregator aggregator;

        public MainWindow(IEventAggregator aggregator)
        {
            InitializeComponent();

            aggregator.GetEvent<MessageEvent>().Subscribe(SubMessage);
            aggregator.GetEvent<TestEvent>().Subscribe(SubTestClass);
            this.aggregator = aggregator;
        }

        private void SubTestClass(Test test)
        {
            MessageBox.Show($"接受到消息:{test.Name} + {test.Age}");
            aggregator.GetEvent<TestEvent>().Unsubscribe(SubTestClass);
        }

        private void SubMessage(string obj)
        {
            MessageBox.Show($"接受到消息:{obj}");
            aggregator.GetEvent<MessageEvent>().Unsubscribe(SubMessage);
        }
    }
}
